3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
A coordinate system (or space ) is any system of assigning planar or spatial positions to objects. In general, QuickDraw 3D operates with rectilinear or Cartesian coordinate systems, in which the position of a point in a plane or in space is determined by projecting the point onto the coordinate axes, which are mutually perpendicular lines that intersect at a point called the origin . By convention, the origin is the planar point (0, 0) or the spatial point (0, 0, 0). Figure 3 shows a Cartesian coordinate system that is right-handed (that is, if the thumb of the right hand points in the direction of the positive x axis and the index finger points in the direction of the positive y axis, then the middle finger points in the direction of the positive z axis).
Figure 3 A right-handed Cartesian coordinate system
You can, for certain purposes, specify positions using other types of coordinate systems, such as the polar coordinate system (a system of assigning planar positions to objects in terms of their distances r from the origin along a ray that forms a given angle with a fixed coordinate line) or the spherical coordinate system (a system of assigning spatial positions to objects in terms of their distances r from the origin along a ray that forms a given angle with a fixed coordinate line and another angle with another fixed coordinate line). QuickDraw 3D provides routines you can use to convert among these three types of coordinate systems. See the chapter "Mathematical Utilities" for details. Unless noted differently, this book always uses Cartesian coordinate systems.
QuickDraw 3D, like virtually all other 3D graphics systems, defines several distinct coordinate systems and maintains transforms that it uses to convert one coordinate system into another.
Because it's often useful to define an object once and then to create multiple copies of that object for placement at different positions and orientations, QuickDraw 3D supports a local coordinate system for each object you define. An object's local coordinate system is simply the coordinate system in which it is specified (that is, that determines the values you specify in the relevant data structure). Any given object can be defined using any of infinitely many local coordinate systems. Usually, you'll pick a local coordinate system whose origin coincides with some part of the object. For instance, it's quite natural to define a box using a local coordinate system whose origin is at the box's origin, and whose axes coincide with the box's axes.
A local coordinate system is sometimes called an object coordinate system or a modeling coordinate system, and the space it defines is the object space or modeling space.
The world coordinate system (or world space ) defines the locations of all geometric objects as they exist at rendering or picking time, with all applicable transforms acting on them. It's important to note that world space is relevant only within a submitting loop, because the transforms that relocate or reorient an object must be applied to the object to determine its position and orientation in world coordinates.
The world coordinate system is sometimes called the global coordinate system or the application coordinate system, and the space it defines is the global space or application space.
You can create copies of an object and place them at different locations by applying different transforms to each copy. A transform changes an object's position or orientation in world coordinates, but not its local coordinates. In other words, if you use the function Q3Box_GetOrigin with two copies of a single box, the function always returns the same origin for each box, whether or not transforms have been applied to one or both of the copies.
The relationship between an object's local coordinate system and the world coordinate system is specified by that object's local-to-world transform. For objects that have no transforms applied to them at rendering time, the local-to-world transform can be represented by the identity matrix, in which case the local coordinate system of that object and the world coordinate system coincide. If one or more transforms is applied to the object at rendering time, the world space location of the object is determined by taking its local space position and applying the transforms to it.
A world coordinate system defines the relative positions and sizes of geometric objects. When an object is rendered in a view, the view's camera specifies yet another coordinate system, the camera coordinate system (or camera space ). A camera coordinate system is defined by the camera placement structure associated with the camera, which is defined like this:
typedef struct TQ3CameraPlacement {
TQ3Point3D cameraLocation;
TQ3Point3D pointOfInterest;
TQ3Vector3D upVector;
} TQ3CameraPlacement;
See the chapter "Camera Objects" for complete information about the camera placement structure.
The cameraLocation field specifies the origin of the camera coordinate system. The pointOfInterest field specifies the z axis of the camera coordinate system, and the upVector field specifies the y axis of the camera coordinate system. The x axis of the camera coordinate system is determined by the left-hand rule. Figure 4 shows a camera coordinate system and its relation to the world coordinate system. In this figure, the camera is set to take an isometric view of the box whose origin is at the origin of the world coordinate system.
Figure 4 A camera coordinate system
As you know, a camera specifies a method of projecting a three-dimensional model onto a two-dimensional plane, called the view plane. The camera, the view plane, and the hither and yon clipping planes together define the part of the model that is projected onto that view plane. As you can see in Figure 9-7 , these objects define a rectangular frustum known as the viewing box. When perspective camera is used, the camera, the view plane, and the hither and yon clipping planes define a pyramidal frustum known as the viewing frustum (see Figure 9-5 ). Because a camera and its camera coordinate system determine a unique view frustum, camera space is also called frustum space.
The final step in creating an image of a model is to map the two-dimensional image projected onto the view plane into the draw context associated with a view. In general, the draw context specifies a window on a screen or other display device that is to contain all or part of the view plane image. Accordingly, QuickDraw 3D maintains, for each draw context, a window coordinate system (or window space ) that defines the position of objects in the draw context. Figure 5 shows a window coordinate system.
Figure 5 A window coordinate system
A window coordinate system is sometimes called a screen coordinate system or a draw context coordinate system, and the space it defines is the screen space or draw context space.
In addition to the local-to-world transform (which defines the relationship between an object's local coordinate system and the world coordinate system), QuickDraw 3D also maintains a world-to-frustum transform (which defines the relationship between the world coordinate system and the frustum coordinate system) and a frustum-to-window transform (which defines the relationship between a frustum coordinate system and a window coordinate system). See Figure 6 . You can, if necessary, get a matrix representation of these three transforms. See the chapter "View Objects" for details.
The world-to-frustum transform is actually the product of two transforms specified by matrices, the view orientation matrix and the view mapping matrix. The view orientation matrix rotates and translates the view's camera so that it is pointing down the negative z axis. The view mapping matrix transforms the viewing frustum into a standard rectangular solid. This standard rectangular solid is a box containing x values from -1 to 1, y values from -1 to 1, and z values from 0 to -1. The far clipping plane is the plane defined by the equation z = - 1, and the near clipping plane is the plane defined by the equation z = 0.
With a perspective camera, the view mapping matrix performs most of the work of projection. The objects transformed by the world-to-frustum transform are still 3D, but it's easy to get the 2D projection onto the view plane by simply dropping the z coordinate of each rendered point.
Figure 6 View state transformations
Previous | QD3D Book | Overview | Chapter Contents | Next |